package com.changgou.seckill.controller;

import com.changgou.seckill.pojo.SeckillGoods;
import com.changgou.seckill.service.SeckillGoodsService;
import com.changgou.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 秒杀商品controller
 */
@RestController
@RequestMapping("/seckillgoods")
public class SeckillGoodsController {

    @Autowired
    private SeckillGoodsService seckillGoodsService;

    /**
     * 根据时间菜单, 加载秒杀商品列表数据返回
     * @param time 传入的时间菜单, 年-月-日 时:分:秒 格式
     * @return
     */
    @GetMapping("/list/{time}")
    public List<SeckillGoods> list(@PathVariable(value = "time") String time) {
        //将年月日十分秒格式, 格式化成年月日小时格式
        String redisKey = DateUtil.formatStr(time);
        //调用service查询秒杀商品数据
        List<SeckillGoods> list = seckillGoodsService.list(redisKey);
        return list;
    }
}
